package cn.com.blueInfo.bpm.person.controller;

import cn.com.blueInfo.bpm.common.controller.BaseController;
import cn.com.blueInfo.bpm.common.validation.Create;
import cn.com.blueInfo.bpm.common.validation.Update;
import cn.com.blueInfo.bpm.common.validation.UpdatePartial;
import cn.com.blueInfo.bpm.person.request.OrganizationDTO;
import cn.com.blueInfo.bpm.person.response.OrganizationVO;
import cn.com.blueInfo.bpm.person.service.OrganizationService;
import cn.com.blueInfo.utils.result.ResultInfo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.groups.Default;
import java.util.List;

/**
 * 组织结构信息表 前端控制器
 * @author suxch
 * @since 2025-08-24 01:39:52
 */
@Tag(name = "组织结构信息 接口")
@RestController
@RequestMapping("/person/organization")
public class OrganizationController extends BaseController {

    @Autowired
    private OrganizationService organizationService;

    /**
     * 新建组织结构信息
     * @param organizationDTO 组织结构信息参数
     * @return ResultInfo
     */
    @Operation(summary = "新增组织结构信息")
    @PostMapping("/addInfo")
    public ResultInfo<Integer> createOrganization(
            @Validated({Create.class, Default.class}) @RequestBody OrganizationDTO organizationDTO) {
        return organizationService.addOrganization(organizationDTO);
    }

    /**
     * 批量新建组织结构信息
     * @param organizationDTOList 组织结构信息参数列表
     * @return ResultInfo
     */
    @Operation(summary = "批量新建组织结构信息")
    @PostMapping("/addInfoList")
    public ResultInfo<Integer> batchCreateOrganization(
            @Validated({Create.class, Default.class}) @RequestBody List<OrganizationDTO> organizationDTOList) {
        return organizationService.batchAddOrganization(organizationDTOList);
    }

    /**
     * 根据ID删除组织结构信息
     * @param organizationId 组织结构信息ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID删除组织结构信息")
    @DeleteMapping("/removeInfo/{organizationId}")
    public ResultInfo<Integer> deleteOrganizationById(
            @Parameter(name = "ID") @PathVariable Long organizationId) {
        return organizationService.removeOrganization(organizationId);
    }

    /**
     * 批量根据ID删除组织结构信息
     * @param organizationIdList 组织结构信息ID列表
     * @return ResultInfo
     */
    @Operation(summary = "批量根据ID删除组织结构信息")
    @DeleteMapping("/removeInfoList/{organizationIdList}")
    public ResultInfo<Integer> batchDeleteOrganizationById(
            @Parameter(name = "ID") @PathVariable List<Long> organizationIdList) {
        return organizationService.batchRemoveOrganization(organizationIdList);
    }

    /**
     * 根据ID全量更新组织结构信息
     * @param organizationId 组织结构信息ID
     * @param organizationDTO 组织结构信息参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID全量更新组织结构信息")
    @PutMapping("/modifyInfo/{organizationId}")
    public ResultInfo<Integer> updateOrganizationFull(
            @Parameter(name = "ID") @PathVariable Long organizationId,
            @Validated({Update.class, Default.class}) @RequestBody OrganizationDTO organizationDTO) {
        validateUpdateId(organizationId, organizationDTO.getId());
        return organizationService.modifyOrganization(organizationDTO);
    }

    /**
     * 根据ID部分更新组织结构信息
     * @param organizationId 组织结构信息ID
     * @param organizationUpdatePartialDTO 组织结构信息参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID部分更新组织结构信息")
    @PatchMapping("/modifyPartialInfo/{organizationId}")
    public ResultInfo<Integer> updateOrganizationPartial(
            @Parameter(name = "ID") @PathVariable Long organizationId,
            @Validated({UpdatePartial.class, Default.class}) @RequestBody
            OrganizationDTO.UpdatePartialDTO organizationUpdatePartialDTO) {
        validateUpdateId(organizationId, organizationUpdatePartialDTO.getId());
        return organizationService.modifyOrganizationPartial(organizationUpdatePartialDTO);
    }

    /**
     * 根据ID查询组织结构信息
     * @param organizationId 组织结构信息ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID查询组织结构信息")
    @GetMapping("/getInfo/{organizationId}")
    public ResultInfo<OrganizationVO> getOrganizationById(
            @Parameter(name = "ID") @PathVariable Long organizationId) {
        return organizationService.queryOrganizationById(organizationId);
    }

    /**
     * 分页查询组织结构信息
     * @param organizationQueryDTO 组织结构信息参数
     * @return ResultInfo
     */
    @Operation(summary = "分页查询组织结构信息")
    @GetMapping("/getInfos")
    public ResultInfo<Page<OrganizationVO>> getOrganizationPage(
            @Validated OrganizationDTO.QueryDTO organizationQueryDTO) {
        return organizationService.queryOrganizationPage(organizationQueryDTO);
    }

    /**
     * 根据条件查询组织结构信息
     * @param organizationQueryDTO 组织结构信息参数
     * @return ResultInfo
     */
    @Operation(summary = "根据条件查询组织结构信息")
    @GetMapping("/getInfoList")
    public ResultInfo<List<OrganizationVO>> getOrganizationList(
            @Validated OrganizationDTO.QueryDTO organizationQueryDTO) {
        return organizationService.queryOrganizationList(organizationQueryDTO);
    }

}
